﻿using SIAKAD.Helper;
using SIAKADCORE.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SIAKAD.Mahasiswas
{
    public partial class GantiPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckSession();
        }

        private void CheckSession()
        {
            if (Session["siakad"] != null && Session["siakad"] is SIAKADCORE.Models.Login)
            {
                if ((Session["siakad"] as SIAKADCORE.Models.Login).UserType != SIAKADCORE.Models.LoginType.Mahasiswa)
                {
                    Response.Redirect(SiteMapHelper.Check((Session["siakad"] as SIAKADCORE.Models.Login)), false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    this.litName.Text = MahasiswaController.GetName((Session["siakad"] as SIAKADCORE.Models.Login).IdLogin);
                }
            }
            else
            {
                Response.Redirect("/Login.aspx");
            }
        }

        protected void lnkLogout_Click(object sender, EventArgs e)
        {
            Session.Clear();
            CheckSession();
        }

        protected void btSubmit_Click(object sender, EventArgs e)
        {
            bool flag = LoginController.CheckPassword((Session["siakad"] as SIAKADCORE.Models.Login).Username, txtPasswordLama.Text);
            if (!flag)
            {
                this.pnlSukses.Attributes["class"] = "panel panel-success hidden";
                this.pnlTidakSama.Attributes["class"] = "panel panel-danger";
            }
            else
            {
                this.pnlTidakSama.Attributes["class"] = "panel panel-danger hidden";
                if (LoginController.GantiPassword((Session["siakad"] as SIAKADCORE.Models.Login).Username, txtPasswordBaru.Text))
                {
                    this.pnlSukses.Attributes["class"] = "panel panel-success";
                }
            }
        }
    }
}